//alert(winHeight = document.documentElement.clientHeight);
//alert(winHeight = document.body.clientHeight);
//alert(winHeight = window.innerHeight);
var oJs1=document.getElementsByClassName("js1");
var oBtn1_pp=document.getElementsByClassName("num1-count");
var oBtn2_pp=document.getElementsByClassName("num2-count");
var oD1=oJs1[0].getElementsByTagName("div");
var oD2=oJs1[1].getElementsByTagName("div");
var oPice=document.getElementsByClassName("pice-pp");

for(var i=0;i<oBtn1_pp.length;i++) {
    oBtn1_pp[i].index=i;
    oBtn1_pp[i].onclick = function () {
        if(oD1[3].innerHTML-0||this.index==1){
        oD1[3].innerHTML = parseInt(oD1[3].innerHTML) +(2*this.index-1);}
        oD1[5].innerHTML = parseFloat(oD1[1].innerHTML) * parseInt(oD1[3].innerHTML);
        if (parseFloat(oD1[5].innerHTML) == parseInt(oD1[5].innerHTML)) {
            oD1[5].innerHTML += ".00";
        }
        var sum=0;
        for(var j=0;j<oJs1.length; j++){
            sum=parseFloat(sum);
            sum+=parseFloat(oJs1[j].getElementsByTagName("div")[5].innerHTML);
            if(sum==parseInt(sum)){sum+=".00";}
        }
        oPice[0].innerHTML="￥"+sum;
        oPice[1].innerHTML="￥"+sum;
    }
}
for(var i=0;i<oBtn2_pp.length;i++) {
    oBtn2_pp[i].index=i;
    oBtn2_pp[i].onclick = function () {
        if(oD2[3].innerHTML-0||this.index==1){
        oD2[3].innerHTML = parseInt(oD2[3].innerHTML) + (2 * this.index - 1);  }
        oD2[5].innerHTML = parseFloat(oD2[1].innerHTML) * parseInt(oD2[3].innerHTML);
        if (parseFloat(oD2[5].innerHTML) == parseInt(oD2[5].innerHTML)) {
            oD2[5].innerHTML += ".00";
        }
        var sum=0;
        for(var j=0;j<oJs1.length; j++){
            sum=parseFloat(sum);
            sum+=parseFloat(oJs1[j].getElementsByTagName("div")[5].innerHTML);
            if(sum==parseInt(sum)){sum+=".00";}
        }
        oPice[0].innerHTML="￥"+sum;
        oPice[1].innerHTML="￥"+sum;
    }
}


var oJs2=document.getElementsByClassName("pay-pp")[0];
var oP1=oJs2.getElementsByTagName("p")[0];
var oPay=document.getElementsByClassName("pay-pic");
var tag=true;
oJs2.onmouseover=function(){
    oP1.style.borderBottomColor="#e01222";
    oP1.style.borderBottomWidth="2px";
    oP1.style.borderBottomStyle="solid";
    //oP1.style.backgroundColor="#e01222";
    //oP1.style.color="#fff";
}
oJs2.onmouseout=function(){
    oP1.style.borderBottomWidth="0";
    //oP1.style.backgroundColor="transparent";
   // oP1.style.color="#000";
}
for( i=0; i<oPay.length;i++) {
    oPay[i].onmouseover = function () {
        var oImg=this.getElementsByTagName("img")[0];
        oImg.style.zIndex="2";
        oImg.style.width=oImg.offsetWidth+13+"px";
        oImg.style.height=oImg.offsetHeight+8+"px";
    }
    oPay[i].onmouseout = function () {
        var oImg=this.getElementsByTagName("img")[0];
        oImg.style.zIndex="0";
        oImg.style.width=oImg.offsetWidth-13+"px";
        oImg.style.height=oImg.offsetHeight-8+"px";
    }
    oPay[i].onclick=function(ev){
        ev=ev||event;
        ev.cancelBubble=true;
        if(!tag){
            for(var j=0;j<oPay.length;j++){
                oPay[j].style.borderWidth="0";}
        }else{
            tag=false;
        }
        this.style.borderWidth="1px";
        this.style.borderColor="#e01222";
        this.style.borderStyle="solid";
    }
}

var oJs3=document.getElementsByClassName("log")[0];
var oP2=oJs3.getElementsByTagName("p")[0];
var oLog=document.getElementsByClassName("log-pic");
var tag=true;
oJs3.onmouseover=function(){
    oP2.style.borderBottomColor="#e01222";
    oP2.style.borderBottomWidth="2px";
    oP2.style.borderBottomStyle="solid";
    //oP2.style.backgroundColor="#e01222";
    //oP2.style.color="#fff";
}
oJs3.onmouseout=function(){
    oP2.style.borderBottomWidth="0";
   // oP2.style.backgroundColor="transparent";
    //oP2.style.color="#000";
}
for( i=0; i<oLog.length;i++) {
    oLog[i].onmouseover = function () {
            var oImg=this.getElementsByTagName("img")[0];
            oImg.style.zIndex="2";
            oImg.style.width=oImg.offsetWidth+13+"px";
            oImg.style.height=oImg.offsetHeight+8+"px";
        }
    oLog[i].onmouseout = function () {
        var oImg=this.getElementsByTagName("img")[0];
        oImg.style.zIndex="2";
        oImg.style.width=oImg.offsetWidth-13+"px";
        oImg.style.height=oImg.offsetHeight-8+"px";
    }
    oLog[i].onclick=function(){
        if(!tag){
            for(var j=0;j<oLog.length;j++){
                oLog[j].style.borderWidth="0";}
        }else{
            tag=false;
        }
        this.style.borderWidth="1px";
        this.style.borderColor="#e01222";
        this.style.borderStyle="solid";
    }
}

var oJs4=document.getElementById("d6");
var oBtn3=oJs4.getElementsByTagName("input");
var oD3=oJs4.getElementsByTagName("div");
var oUl=oJs4.getElementsByTagName("ul");      //下拉框要动态（滚动条）
var oLi1=oUl[0].getElementsByTagName("li");
var oLi2=oUl[1].getElementsByTagName("li");
oBtn3[1].onclick=function(ev){
    ev=ev||event;
    ev.cancelBubble=true;
    oUl[0].style.display="block";
    for(var i=0;i<oLi1.length;i++){
        oLi1[i].onclick=function(){
            oD3[0].innerHTML=this.innerHTML;
        }
    }
}
oBtn3[2].onclick=function(ev){
    ev=ev||event;
    ev.cancelBubble=true;
    oUl[1].style.display="block";
    for(var i=0;i<oLi2.length;i++){
        oLi2[i].onclick=function(){
            oD3[1].innerHTML=this.innerHTML;
        }
    }
}

var oCount=document.getElementsByClassName("count")[0];
var oJs5=document.getElementsByClassName("address-add")[0];
var oLi3=oJs5.getElementsByTagName("li");
var oAdd=oJs5.getElementsByClassName("add");
var oS2=document.getElementsByClassName("s2");  //编辑
var oS3=document.getElementsByClassName("s3");  //删除
var oPic2=document.getElementsByClassName("p1");  //选中
var oAdd2=document.getElementsByClassName("p2"); //默认地址
var oAdd3=document.getElementsByClassName("moren");//是否设置为默认样式
var oNew_add=document.getElementsByClassName("newadd")[0];
var oCh_add=document.getElementsByClassName("newadd")[1];
var oBtn4=oNew_add.getElementsByClassName("p5");
var address_1=document.getElementById("p4").getElementsByTagName("span")[0];  //最终收货地址和收货人
var man_1=document.getElementById("p5").getElementsByTagName("span")[0];
var oPay_1=document.getElementById("p3").getElementsByTagName("span")[0];
var oT1,oT2,oT3,oT4,oT5,oT6;
oPic2[0].style.borderRightColor="green";
oPic2[0].style.borderBottomColor="green";
oAdd2[0].style.display="block";
oAdd[0].style.opacity="1";
var oAll=document.getElementById("all-address");
oLi3[0].onclick=function(ev){
    ev=ev||event;
    ev.cancelBubble="true";
    oAll.style.overflow="visible";
    oAll.style.height="325px";
    for(var i=0;i<oAdd.length;i++){
    oAdd[i].style.backgroundColor="#fff";
    }
    oAll.style.backgroundColor="#fff";
    oAll.style.borderStyle="solid";
    oAll.style.borderWidth="1px";
    oAll.style.borderColor="#e01222";
}
oLi3[1].onclick=function(ev){
    ev=ev||event;
    ev.cancelBubble=true;
    this.style.backgroundColor="#e01222";
    this.style.color="#fff";
    this.style.textAlign="center";
    oNew_add.style.display="block";
    oCount.style.backgroundColor="rgba(185,185,185,0.5)";
    oBtn3[0].style.backgroundColor="transparent";
    document.getElementById("d4").style.backgroundColor="transparent";
    oBtn1_pp[0].style.backgroundColor="transparent";
    oBtn1_pp[1].style.backgroundColor="transparent";
    oBtn2_pp[0].style.backgroundColor="transparent";
    oBtn2_pp[1].style.backgroundColor="transparent";
}
var oWarn=document.getElementById("warning");
oBtn4[0].onclick=function(ev) {    //保存

    var oC = document.createElement("div");            //动态创建新地址
    oC.className = "add";
    oC.id = "create-count";
    document.getElementById("all-address").insertBefore(oC,oAdd[0]);
    var oc13=document.createElement("span");
    oc13.innerHTML="设置为默认地址";
    oc13.className="moren";
    oC.appendChild(oc13);
    var oc1 = document.createElement("img");
    oc1.src = "./img/count/pic1.png";
    oc1.style.width = "222px";
    oc1.style.height = "3px";
    oc1.id = "pic1";
    oC.appendChild(oc1);
    var oc2=document.createElement("div");
    oc2.id="d2";
    oc2.className="d2";
    oC.appendChild(oc2);
    var oc3=document.createElement("div");
    var oc12=document.createElement("div");
    var oc4=document.createElement("div");
    oc4.innerHTML="收货地址:";
    oc3.id="name";
    oc12.id="num";
    oc4.id="ress";
    oc2.appendChild(oc3);
    oc2.appendChild(oc12);
    oc2.appendChild(oc4);
    var oc5 = document.createElement("div");
    oc5.id = "d3";
    oc5.className = "d3";
    oC.appendChild(oc5);
    var oc6 = document.createElement("span");
    oc6.className = "s2";
    oc6.innerHTML = "编辑";
    var oc7 = document.createElement("img");
    oc7.src = "./img/count/pic4.png";
    oc7.style.width = "2px";
    oc7.style.height = "13px";
    oc7.id = "pic4";
    var oc8 = document.createElement("span");
    oc8.className = "s3";
    oc8.innerHTML = "删除";
    oc5.appendChild(oc6);
    oc5.appendChild(oc7);
    oc5.appendChild(oc8);
    var oc9 = document.createElement("img");
    oc9.src = "./img/count/pic1.png";
    oc9.style.width = "222px";
    oc9.style.height = "3px";
    oc9.id = "pic2";
    oC.appendChild(oc9);
    var oc10 = document.createElement("div");
    oc10.id = "pic3";
    oc10.className = "p1";
    oc10.innerHTML = "√";
    oC.appendChild(oc10);
    var oc11 = document.createElement("div");
    oc11.id = "d1";
    oc11.className = "p2";
    oc11.innerHTML = "默认地址";
    oC.appendChild(oc11);                //创建结束
    oT1 = oNew_add.getElementsByClassName("t1")[0].value;
    oT2 = oNew_add.getElementsByClassName("t1")[1].value;
    var Q1 = document.getElementById("t2");
    var index1 = Q1.selectedIndex;
    oT3 = Q1.options[index1].text;
    var Q2 = document.getElementById("t3");
    var index2 = Q2.selectedIndex;
    oT4 = Q2.options[index2].text;
    var Q3 = document.getElementById("t4");
    var index3 = Q3.selectedIndex;
    oT5 = Q3.options[index3].text;
    oT6 = textear1.value;
    if(oT1&&oT2){
        oC.style.display="block";
        oNew_add.style.display = "none";
        oCount.style.backgroundColor = "transparent";
        oLi3[1].style.backgroundColor = "transparent";
        oLi3[1].style.color = "black";
        oLi3[1].style.textAlign = "left";
        document.getElementById("d4").style.backgroundColor="#f5f5f5";
        oBtn1_pp[0].style.backgroundColor="#f5f5f5";
        oBtn1_pp[1].style.backgroundColor="#f5f5f5";
        oBtn2_pp[0].style.backgroundColor="#f5f5f5";
        oBtn2_pp[1].style.backgroundColor="#f5f5f5";
    }else{
        ev=ev||event;
        ev.cancelBubble=true;
        oWarn.style.display="block";
        oWarn.style.backgroundColor="#fff";
        //oNew_add.style.display="none";
    }
    var s = oC.getElementsByTagName("div")[0].getElementsByTagName("div");
    s[0].innerHTML = oT1;
    s[1].innerHTML = oT2;
    s[2].innerHTML +="&nbsp;&nbsp;"+oT3 + "&nbsp;&nbsp;" + oT4 + "&nbsp;&nbsp;" + oT5 + "&nbsp;&nbsp;" + oT6;



    for (var i = 0; i < oAdd.length; i++) {                //选中
        oAdd[i].index = i;
        oAdd[i].onclick = function () {
            var oop=this.getElementsByTagName("div")[0].getElementsByTagName("div");
            address_1.innerHTML=oop[2].innerHTML;
            man_1.innerHTML=oop[0].innerHTML+"&nbsp;&nbsp;"+oop[1].innerHTML;
            for (var j = 0; j < oAdd.length; j++) {
                if (j == this.index) {
                    oPic2[j].style.borderRightColor = "green";
                    oPic2[j].style.borderBottomColor = "green";
                    if(oAdd2[j].style.display!="block"){
                        oAdd3[j].style.opacity="1";
                        oAdd3[j].index=j;
                        oAdd3[j].onmouseover=function(){
                            this.style.color="#666";
                            this.style.fontSize="14px";
                            this.onclick=function(){
                                oAdd3[this.index].style.opacity="0";
                                oAdd2[this.index].style.display="block";
                                for(var k=0;k<oAdd.length;k++){
                                    if(k!=this.index){
                                        oAdd2[k].style.display="none";
                                    }
                                }
                            }
                        }
                        oAdd3[j].onmouseout=function(){
                            this.style.color="#ccc";
                            this.style.fontSize="10px";
                            //oAdd3[this.index].style.opacity="0";
                        }
                    }
                    this.style.opacity = "1";
                } else {
                    oPic2[j].style.borderRightColor = "transparent";
                    oPic2[j].style.borderBottomColor = "transparent";
                    oAdd3[j].style.opacity= "0";
                    oAdd[j].style.opacity = "0.5";
                }
            }
        }
    }

    for(var i=0;i<oAdd.length;i++){        //编辑
        oS2[i].index=i;
        oS2[i].onclick=function(){
            var cnt=this.index;
            oCh_add.style.display="block";
            oCount.style.backgroundColor="rgba(185,185,185,0.5)";
            oCh_add.getElementsByClassName("p5")[0].onclick=function(){
                for(var i=0;i<oAdd.length;i++){
                    if(i==cnt){
                        var oopar=oAdd[i].getElementsByTagName("div")[0].getElementsByTagName("div");
                    }
                }

                oT1=oCh_add.getElementsByClassName("t1")[0].value;
                oT2=oCh_add.getElementsByClassName("t1")[1].value;
                var Q4=document.getElementById("t5");
                var index4=Q4.selectedIndex;
                oT3=Q4.options[index4].text;
                var Q5=document.getElementById("t6");
                var index5=Q5.selectedIndex;
                oT4=Q5.options[index5].text;
                var Q6=document.getElementById("t7");
                var index6=Q6.selectedIndex;
                oT5=Q6.options[index6].text;
                oT6=textear2.value;
                if(oT1==0){
                    oopar[0].innerHTML=oopar[0].innerHTML;
                }else{
                    oopar[0].innerHTML=oT1;
                }
                if(oT2==0){
                    oopar[1].innerHTML=oopar[1].innerHTML;
                }else{
                    oopar[1].innerHTML=oT2;
                }

                if(oT6==0){
                    oopar[2].innerHTML=oopar[2].innerHTML;
                }else{
                    oopar[2].innerHTML="收货地址："+oT3+"&nbsp;&nbsp;"+oT4+"&nbsp;&nbsp;"+oT5+"&nbsp;&nbsp;"+oT6;
                }
                if( oAdd[cnt].style.opacity=="1"){
                    var oop=oAdd[cnt].getElementsByTagName("div")[0].getElementsByTagName("div");
                    address_1.innerHTML=oop[2].innerHTML;
                    man_1.innerHTML=oop[0].innerHTML+"&nbsp;&nbsp;"+oop[1].innerHTML;
                }
                oCh_add.style.display="none";
                oCount.style.backgroundColor="transparent";
            }
            oCh_add.getElementsByClassName("p5")[1].onclick=function(){
                oCh_add.style.display="none";
                oCount.style.backgroundColor="transparent";
            }
        }
    }
    for(var i=0;i<oAdd.length;i++){        //删除
        oS3[i].index=i;
        oS3[i].onclick=function(){
            if(confirm("确定要删除吗？")){
                this.parentNode.parentNode.style.display="none";
            }
        }
    }


}

oBtn4[1].onclick=function(){     //取消
    oNew_add.style.display="none";
    oCount.style.backgroundColor="transparent";
    oLi3[1].style.backgroundColor="transparent";
    oLi3[1].style.color="black";
    oLi3[1].style.textAlign="left";
    document.getElementById("d4").style.backgroundColor="#f5f5f5";
    oBtn1_pp[0].style.backgroundColor="#f5f5f5";
    oBtn1_pp[1].style.backgroundColor="#f5f5f5";
    oBtn2_pp[0].style.backgroundColor="#f5f5f5";
    oBtn2_pp[1].style.backgroundColor="#f5f5f5";
}


for(var i=0;i<oAdd.length;i++){                //选中
    oAdd[i].index=i;
    oAdd[i].onclick=function() {
        var oop=this.getElementsByTagName("div")[0].getElementsByTagName("div");
        address_1.innerHTML=oop[2].innerHTML;
        man_1.innerHTML=oop[0].innerHTML+"&nbsp;&nbsp;"+oop[1].innerHTML;
        for(var j=0;j<oAdd.length;j++){
            if(j==this.index){
                oPic2[j].style.borderRightColor="green";
                oPic2[j].style.borderBottomColor="green";
                if(oAdd2[j].style.display!="block"){
                    oAdd3[j].style.opacity="1";
                    oAdd3[j].index=j;
                    oAdd3[j].onmouseover=function(){
                        this.style.color="#666";
                        this.style.fontSize="14px";
                        this.onclick=function(){
                            oAdd3[this.index].style.opacity="0";
                            oAdd2[this.index].style.display="block";
                            for(var k=0;k<oAdd.length;k++){
                                if(k!=this.index){
                                    oAdd2[k].style.display="none";
                                }
                            }
                        }

                    }
                    oAdd3[j].onmouseout=function(){
                        this.style.color="#ccc";
                        this.style.fontSize="10px";
                       // oAdd3[this.index].style.opacity="0";
                    }
                }
                this.style.opacity="1";
            }else{
                oPic2[j].style.borderRightColor="transparent";
                oPic2[j].style.borderBottomColor="transparent";
                oAdd3[j].style.opacity="0";
                oAdd[j].style.opacity="0.5";
            }
        }
    }
}




for(var i=0;i<oAdd.length;i++){        //编辑
    oS2[i].index=i;
    oS2[i].onclick=function(){
        var cnt=this.index;
        oCh_add.style.display="block";
        oCount.style.backgroundColor="rgba(185,185,185,0.5)";
        oCh_add.getElementsByClassName("p5")[0].onclick=function(){
            for(var i=0;i<oAdd.length;i++){
                if(i==cnt){
                    var oopar=oAdd[i].getElementsByTagName("div")[0].getElementsByTagName("div");
                }
            }
            oT1=oCh_add.getElementsByClassName("t1")[0].value;
            oT2=oCh_add.getElementsByClassName("t1")[1].value;
            var Q4=document.getElementById("t5");
            var index4=Q4.selectedIndex;
            oT3=Q4.options[index4].text;
            var Q5=document.getElementById("t6");
            var index5=Q5.selectedIndex;
            oT4=Q5.options[index5].text;
            var Q6=document.getElementById("t7");
            var index6=Q6.selectedIndex;
            oT5=Q6.options[index6].text;
            oT6=textear2.value;
            if(oT1==0){
                oopar[0].innerHTML=oopar[0].innerHTML;
            }else{
                oopar[0].innerHTML=oT1;
            }
            if(oT2==0){
                oopar[1].innerHTML=oopar[1].innerHTML;
            }else{
                oopar[1].innerHTML=oT2;
            }
            if(oT6==0){
                oopar[2].innerHTML=oopar[2].innerHTML;
            }else{
                oopar[2].innerHTML="收货地址："+oT3+"&nbsp;&nbsp;"+oT4+"&nbsp;&nbsp;"+oT5+"&nbsp;&nbsp;"+oT6;
            }
            if( oAdd[cnt].style.opacity=="1"){
                var oop=oAdd[cnt].getElementsByTagName("div")[0].getElementsByTagName("div");
                address_1.innerHTML=oop[2].innerHTML;
                man_1.innerHTML=oop[0].innerHTML+"&nbsp;&nbsp;"+oop[1].innerHTML;
            }
            oCh_add.style.display="none";
            oCount.style.backgroundColor="transparent";
        }
        oCh_add.getElementsByClassName("p5")[1].onclick=function(){
            oCh_add.style.display="none";
            oCount.style.backgroundColor="transparent";
        }
    }
}
for(var i=0;i<oAdd.length;i++){        //删除
    oS3[i].index=i;
    oS3[i].onclick=function(){
       if(confirm("确定要删除吗？")){
           this.parentNode.parentNode.style.display="none";
       }
    }
}

oAll.onclick=function(ev){
    ev=ev||event;
    ev.cancelBubble="true";
}
document.getElementById("d9").onclick=function(ev){
    ev=ev||event;
    ev.cancelBubble="true";
    window.location.href="pay_m.html#"+(oPice[1].innerHTML);

}

document.onclick=function(){
    oLi3[1].style.backgroundColor="transparent";
    oLi3[1].style.color="black";
    oLi3[1].style.textAlign="left";

    oAll.style.height="160px";
    oAll.style.overflow="hidden";
    for(var i=0;i<oAdd.length;i++){
        oAdd[i].style.backgroundColor="transparent";
    }
    oAll.style.backgroundColor="transparent";
    oAll.style.borderWidth="0";

    oUl[0].style.display="none";
    oUl[1].style.display="none";
if(oWarn.style.display=="block"){
    oWarn.style.display="none";
}

}


